<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8")>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>个人注册</title>
</head>
<script src="../../js/edition.js"></script> 
<link rel="stylesheet" href="../../css/base.css">
<script>
        document.write("<l"+"ink rel='stylesheet' href='../../css/style.css?version="+edition+"'>")
</script>
<script>
        document.write("<l"+"ink rel='stylesheet' href='../../css/popover.css?version="+edition+"'>")
</script>
<script src="../../js/jquery.js"></script>
<script src="../../js/template.js"></script>
<script> 
        document.write("<s"+"cript type='text/javascript' src='../../js/url.js?version="+edition+"'></scr"+"ipt>"); 
</script>
<script src="../../js/login_foot.js"></script>
<script src="../../js/register_header.js"></script>
<script src="../../js/popover.js"></script>
<body>
    <div class="header_t">
        <script>
            $(function(){
                register_header()
            })    
        </script>
    </div>
    <div class="register_tit">
            <ul>
                <li class="active" style="margin-left:138px;">个人注册</li>
                <li onclick="onc()">公司注册</li>
            </ul>
    </div>
    <!-- action="/shop/login/register" method="post" -->
    <form class="register_tab"> 
        <input type="hidden" name="memberType" value="1">
        <div class="register_bg">
            <ul>
                <li>
                    <em>手机号码</em>
                    <input type="text" name="phone" id="phone" placeholder="请输入手机号码">
                    <div class="error">请输入正确的手机号</div>
                </li>
                <li>
                        <em>验<i style="width: 6px; display: inline-block;"></i>证<i style="width: 6px; display: inline-block;"></i>码</em>
                        <input type="text" name='phoneCode' id="verification" placeholder="请输入验证码">
                        <a id="phoneCode">获取短信验证码</a>
                        <a style="display:none" class="phoneCode"></a>
                        <div class="error">验证码错误</div>
                </li>
                <li>
                        <em>密<i style="width: 24px; display: inline-block;"></i>码</em>
                        <input type="password" maxlength="18" name="password" id="password" placeholder="请输入密码">
                        <div class="error">请输入最少6位数的密码</div>
                </li>
                <li>
                        <em>推<i style="width: 6px; display: inline-block;"></i>荐<i style="width: 6px; display: inline-block;"></i>码</em>
                        <input name="inviteCode" id="inviteCode" type="text" placeholder="非必填">
                </li>
            </ul>
            <div class="select">
                    <p class="fl_l"><label for=""><input type="checkbox" name="" id="" checked="checked">我已同意<a href="javascript:;" style="color:#006699;">《购吧用户协议》</a></label></p>
            </div>
            <div class="error_text"></div>
            <div class="login_sub"><input type="submit" value="立即注册" id="login_sub"></div>   
        </div>    
    </form>
    <div class="login_foot" id="login_foot">
            <script>
                $(function(){
                    login_foot();
                })
            </script>
        </div>    
</body>
<script>
function onc(){
    window.location.href='register_company.html'
}
function ajax_form(){
    // 判断底部是否定位
    var w_h=$(window).height();
    $('.register_tab').css('min-height',(w_h-425)+'px');
    $('#phoneCode').click(function(){
        var phone = $('#phone').val();
        var url= new_url+"shop/login/sendPhoneCode"; 
        var time='60'
        function tim(){
            setTimeout(function(){                                               
            if(time>'0'){
                tim();
                time --
                $('#phoneCode').hide()
                $('.phoneCode').show()
                // $('.register_bg ul li').eq(1).append('<a class="phoneCode"></a>')
                $('.phoneCode').text(time+'s重新获取');
            }
            else{
                $('.phoneCode').hide()
                $('#phoneCode').show()
                $('#phoneCode').text('重新获取验证码')    
            }    
            },1000)
        }
        if((/^1(3|4|5|7|8)\d{9}$/.test(phone))){
            tim();
            $.ajax({
                type: "post",
                dataType:'json',
                url: url, 
                data:'phone='+phone,       
                success: function(e){
                    // console.info(e)
                    if(e.code=='0'){
                        tc(e.message);  
                    }
                    else{
                        tc(e.message);
                    }
                }
            });
        }
        else{
            tc('请输入手机号')
        }
    })
    function phone(){    
        var phone = $('#phone').val();  
            if(!(/^1(3|4|5|7|8)\d{9}$/.test(phone))){
                $('#phone').parents('li').addClass('error_bor');
                $('.error_bor').find('.error').show();
                return false;     
            }else{
                $('#phone').parents('li').removeClass('error_bor');
                $('#phone').parents('li').find('.error').hide();
                // return false;
                };    
            if($('#verification').val()==''){
                $('#verification').parents('li').addClass('error_bor'); 
                $('.error_bor').find('.error').show();
                return false; 
            }else{
                $('#verification').parents('li').removeClass('error_bor');
                $('#verification').parents('li').find('.error').hide()
                // return false;
                };
            if($('#password').val().length<6){
                $('#password').parents('li').addClass('error_bor');
                $('.error_bor').find('.error').show();
                return false; 
            }else{
                $('#password').parents('li').removeClass('error_bor');
                $('#password').parents('li').find('.error').hide()
                // return false;
                };  
            if($("input[type='checkbox']").is(":checked")){
                $('.error_text').hide();
                $('.select').removeClass('error_bor')
                return false; 
            }
            else{
                $('.select').addClass('error_bor')
                $('.error_text').show().text('请同意购吧协议');
                            }            
    }
    $('#login_sub').on('click',function(){
        phone(); 
        $('.register_bg ul li input').each(function(index,t){
        $(t).blur(function(){
            phone();
        })
    })
        if($('.register_bg ul li').hasClass('error_bor')||$('.select').hasClass('error_bor')){
            return false;
        }else{
            $.ajax({
            type:'post',
            dataType: 'json',
            data:$(".register_tab").serialize(),
            url:new_url+'shop/login/register',
            success:function(e){
                // console.info(e)
                if(e.code=='0'){
                    tc(e.message);
                    setTimeout(function(){
                        window.location.href='login.html?type=1'
                    },1100)
                }
                else{
                    tc(e.message);
                }
            },
        })
        }
        return false;
    })
    // $('.register_bg ul li input').each(function(index,t){
    //     $(t).blur(function(){
    //         phone();
    //     })
    // })
}ajax_form()
// $(function(){
//     if($.cookie('user')!=''&&$.cookie('user')!=null){
//         window.location.href='/index.html'
//     }
// })
</script>
</html>